package com.nageoffer.shortlink.remote.config;

import com.nageoffer.shortlink.common.dto.admin.biz.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {
    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor userInfoInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                String username = UserContext.getUsername();
                String token = UserContext.getToken();
                if (username!=null) {
                    requestTemplate.header("username",username);
                }
                if (token!=null) {
                    requestTemplate.header("token",token);
                }
            }
        };
    }
}
